import { Geometry } from "./Geometry";
import { any, all, has } from "../core/logic";
import { process } from "../process/worker/process";
/**
 * @class
 * @memberof w.geometry
 */
class RingGeometry extends Geometry {
  /**
   * 圆环平面构造方法
   * @param {*} opts
   * @param {Number} opts.row 【可选值】圆环截面段数，缺省值：50。
   * @param {Number} opts.column 【可选值】圆环段数，缺省值：50。
   * @param {Number} opts.irad 【可选值】圆环内环半径，缺省值：1。
   * @param {Number} opts.orad【可选值】圆环外环半径，缺省值：3。
   * @param {Boolean} opts.back 【可选值】是否开启后台线程构造圆，缺省值：true，在后台进行解析。
   * @example
   * let c=new w.geometry.CubeGeometry({size:[1,1,1]});
   */
  constructor(opts = {}) {
    super(opts);
    this.type = "RingGeometry";
    this.position = null;
    this._row = any(opts.row, 50);
    this._column = any(opts.column, 50);
    this._irad = any(opts.irad, 1);
    this._orad = any(opts.orad, 3);
    this.back = any(opts.back, false);
    this.createRing();
  }
  set back(v){
    this._back = v;
    return this;
  }
  get back(){
    return this._back;
  }
  set row(v){
    this._row = v;
    this.createRing();
    return this;
  }
  get row(){
    return this._row;
  }
  set column(v){
    this._column = v;
    this.createRing();
    return this;
  }
  get column(){
    return this._column;
  }
  set irad(v){
    this._irad = v;
    this.createRing();
    return this;
  }
  get irad(){
    return this._irad;
  }
  set orad(v){
    this._orad = v;
    this.createRing();
    return this;
  }
  get orad(){
    return this._orad;
  }
  createRing() {
    if (all(has(this.irad),has(this.orad),has(this.column),has(this.row))) {
      let info = { back: this.back,irad:this.irad, orad: this.orad,row:this.row,column:this.column, type: "createRing" }
      process(info, (message) => {
        let { position, indices,normal,color } = message.data;
        this.position = new Float32Array(position);
        this.indices = new Uint32Array(indices);
        this.normal = new Float32Array(normal);
        // this.color = new Uint8Array(color);
      })
    }
  }
}

export { RingGeometry }
